using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Obsolete]
public class Glueable : MonoBehaviour
{
    [SerializeField]
    private LayerMask _layer;

    private SpringJoint2D _spring;


    // Start is called before the first frame update
    void Start()
    {
        _spring = GetComponent<SpringJoint2D>();
        _spring.enabled = false;
    }

    // Update is called once per frame
    //void FixedUpdate()
    //{
    //    var results = Physics2D.OverlapCircle(transform.position, 1f, _layer);
    //    if (results != null)
    //    {
    //        if (results.TryGetComponent(out Rigidbody2D body))
    //        {
    //            if (body.gameObject != gameObject)
    //            {
    //                _spring.connectedBody = body;
    //                _spring.enabled = true;
    //            }
    //        }
    //    }
    //}

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.transform.TryGetComponent(out Rigidbody2D body))
        {
            if (body.gameObject != gameObject)
            {
                _spring.connectedBody = body;
                _spring.enabled = true;
            }
        }
    }
}
